/**
 * 版权所有(C)，上海***股份有限公司，2018，所有权利保留。
 * 
 * 项目名：	shop-order-web
 * 文件名：	OrderController.java
 * 模块说明：	
 * 修改历史：
 * 2018年12月30日 - Administrator - 创建。
 */
package com.study.springcloud.shop;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.study.springcloud.shop.order.OrderFeignClient;
import com.study.springcloud.shop.score.ScoreFeignClient;
import com.study.springcloud.shop.stock.StockFeignClient;
import com.study.springcloud.shop.warehouse.WarehouseFeignClient;

/**
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/order/*")
public class OrderController {

  @Autowired
  private OrderFeignClient orderFeignClient;
  @Autowired
  private ScoreFeignClient scoreFeignClient;
  @Autowired
  private StockFeignClient stockFeignClient;
  @Autowired
  private WarehouseFeignClient warehouseFeignClient;

  @RequestMapping(value = "payed", method = RequestMethod.POST)
  @ResponseBody
  public void payed(@RequestBody Order entity) throws Exception {
    System.out.println("订单：" + entity);
    // 修改订单状态
    orderFeignClient.payed(entity);
    // 扣减商品库存
    stockFeignClient.subtractProductStock(entity.getProductId());
    // 仓库发货
    warehouseFeignClient.ship(entity.getProductId());
    // 为用户增加积分
    scoreFeignClient.addUserScore(entity.getUserId());
  }
}
